const Random = Mock.Random

const domain = 'http://mutouyun.com/api'

const User = Mock.mock({
  'user': {
    'id': Random.natural(1, 10000),
    'cName': '@cname',
    'cId': Random.id(),
    'city': Random.city(),
    'tel': '13' + Random.natural(100000000, 999999999),
    'avatar': Random.dataImage('300x250', 'mock的图片'),
    'bankCard|0-5': [Random.natural()],
    'isCertify': Random.boolean(),
    'isSign': Random.boolean()
  }
})

User.user.bankCount = User.user.bankCard.length + '张'

Mock.mock(`${domain}/users`, 'get', User);

Mock.mock(`${domain}/personCertify`, 'post', function(options) {
  let urlobj = {}
  secondurl = options.body.split('&')
  for (let i = 0; i < secondurl.length; i++) {
    let thirdurl = secondurl[i].split('=');
    urlobj[thirdurl[0]] = thirdurl[1];
  }
  console.log(urlobj);
  User.user.cName = urlobj.cName
  User.user.cId = urlobj.cId
  User.user.isSign = true
  return User
});

const Certify = Mock.mock({
  'data': {
    'type|0-1': 0, //0个人 1企业
    'result|0-2': 2, //0验证中 1验证成功 2验证失败
    'user': {
      'cName': '@cname',
      'cType': '身份证',
      'cId': Random.id(),
    }
  }
})

Mock.mock(`${domain}/certify`, 'get', Certify);

const telCode = Mock.mock({
  'data': {
    'telcode': Random.natural('000000', '999999')
  }
})

Mock.mock(`${domain}/telcode`, 'get', telCode);

const StoreAudit = Mock.mock({
  'data': {
    'result|0-2': 1, //0验证中 1验证成功 2验证失败
  }
})

Mock.mock(`${domain}/storeaudit`, 'get', StoreAudit);

const UploadCertify = Mock.mock({
  'data': {
    'cId_front': Random.boolean(), //模拟true表示有，false表示没有
    'cId_back': Random.boolean(),
    'license': false
  }
})

Mock.mock(`${domain}/uploadcertify`, 'post', function(options) {
  return UploadCertify;
});
